 //Initialize Select2 Elements





$("#searchDev").on('click',function(){
	reload(1);
})
reload(1);
function reload(z_index){
	var limit = 10;
	var appKey = $("#appKey").val();
	var devName = $("#devName").val();
	
	var start = (z_index-1)*limit;
	var param = {
		appKey : appKey,
		devName : devName,
		start:start,
		limit:limit,
	}
	loading.show();
	$.ajax({
		url:'/dev/getDevelopers',
		type:'GET',
		data:param
	}).done(function(res){
		loading.hide();
		var result = res.rows;
		var pagefn = doT.template($('#tableDetail01').text());
	    $('#tableList').html(pagefn(result));
	    
	    $('.M-box').pagination({
            totalData:res.results,
            showData:10,
            coping:true,
            current:z_index,    
            prevContent:'<上一页',
            nextContent:'下一页>',
            callback:function(e){
                console.log(e.getCurrent());
                var z_index = e.getCurrent();
                reload(z_index);
            }
        },function(api){
            //console.log('error');
        });
	}).fail(function(res){
		toast.show(res.errorMsg);
	})
}

function addDev(){
	window.location = "/dev/addDev";
}

function deleteDev(appKey,id){
	getModal.show({content:'确定删除？',cb_l:function(){return deleteApiCb(appKey,id)}});
}



function deleteApiCb(appKey,id){
	var param = {
		appKey:appKey,
		id:id
	}
	$.ajax({
		url:'/dev/deleteDeveloperById',
		type:'POST',
		data:param
	}).done(function(res){
		if(res.success){
			toast.show("操作成功");
			reload(1);
		}else{
			toast.show(res.errorMsg);
		}
	}).fail(function(res){
		toast.show(res.errorMsg);
	})
}

function editDev(id){
	window.location = "/dev/addDev?id="+id;
}

function editDevPri(id,name){
	window.location = "/dev/searchPri?id="+id+"&name="+name;
}

function editDevIp(id,name){
	window.location = "/dev/searchIp?id="+id+"&name="+name;
}
